<?php
namespace Index\Controller;
use Think\Controller;
class SettingsController extends CommonController {
    public function indexAction(){


    	$db = '123123';
    	$id = $_SESSION['id'];

    	$sql = "select * from user where id='{$id}'";
    	$info = M()->query($sql);
        $info = current($info);
    	$this->assign('info',$info);
        $this->display();
    }

    public function UpdateAction()
    {
    	 var_dump($_POST);
    }

    // 头像
    public function faceAction()
    {
         $this->display();
    }

    public function UploadAction()
    {
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =      './Uploads/'; // 设置附件上传根目录
        $upload->savePath  =      ''; // 设置附件上传（子）目录
        // 上传文件 
        $info   =   $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功 获取上传文件信息
            foreach($info as $file){
                $face = "/Uploads/".$file['savepath'].$file['savename'];

                $id = $_SESSION['id'];
                $sql = "update user set face='{$face}' where id='{$id}' ";
                $res = M()->execute($sql);
                if($res){
                    $_SESSION['face']= $face;
                    echo json_encode('1');
                }else{
                    echo json_encode('0');
                }
            }
        }
    }



}  

